package czk.concrent.threadpool.newSingleThreadexecutor;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * 单线程线程池
 * 有异常会创建新的线程来继续执行
 * @Author:ChenZhangKun
 * @Date: 2020/6/30 22:52
 */
public class NewSingleThreadExecutorDemo {
    public static void main(String[] args) throws InterruptedException {
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        // 抛异常
        executorService.execute(()->{
            System.out.println("线程一执行 "+1/0);
        });
        TimeUnit.SECONDS.sleep(1);
        // 仍然会执行
        executorService.execute(()->{
            System.out.println("线程二执行 "+2/1);
        });
        // 仍然会执行
        executorService.execute(()->{
            System.out.println("线程三执行 "+3/1);
        });
    }
}
